﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AIMLbot
{
    public class Plugin : Plugins.IPlugin
    {

        #region IPlugin Members
        public string Name { get { return "AI"; } }
        public MSNPSharp.Messenger Messenger { get; set; }
        public Plugin()
        {
            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(createAliceThread), null);
        }
        public string RootStore { get; set; }
        public List<string> Command
        {
            get { return new List<string>(); }
        }

        AIMLbot.Bot alice;
        public string AIName = Plugins.PluginLoader.ScreenName;
        private void createAliceThread(object state)
        {
            if (alice == null)
            {
                try
                {
                    Console.WriteLine("Loading Bot");
                    alice = new AIMLbot.Bot();
                    Console.WriteLine("Loading Bot Settings");                    
                    alice.loadSettings();
                    Console.WriteLine("Loading Bot Brains");
                    alice.loadAIMLFromFiles();
                    Console.WriteLine("Done Loading Bot");
                    AIMLbot.Result result = alice.Chat("Hello", "Console");
                    if (result != null && result.Output != null) Console.WriteLine("Bot Response:" + result.Output);
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Trace.WriteLine("Error Loading Alice Bot Plugin");
                    System.Diagnostics.Trace.WriteLine(exc.ToString());

                }
            }
        }

        public string Chat(string Command, string UserID, string Input)
        {
            return alice.Chat(Input, UserID).Output;
        }

        #endregion
    }
}
